package com.example.demo.server3.template;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;

public class MessageHeader {
    private int Total_Length;
    private int Command_Id;
    private int Sequence_Id;

    public MessageHeader() {
    }

    public MessageHeader(int total_Length, int command_Id, int sequence_Id) {
        Total_Length = total_Length;
        Command_Id = command_Id;
        Sequence_Id = sequence_Id;
    }

    public void structure(ByteBuf byteBuf){
        Total_Length = byteBuf.getInt(0);
        Command_Id = byteBuf.getInt(4);
        Sequence_Id = byteBuf.getInt(8);
    }

    public ByteBuf destruct(){
        ByteBuf byteBuf = Unpooled.buffer(12);
        byteBuf.writeInt(Total_Length);
        byteBuf.writeInt(Command_Id);
        byteBuf.writeInt(Sequence_Id);
        return byteBuf;
    }

    public int getTotal_Length() {
        return Total_Length;
    }

    public void setTotal_Length(int total_Length) {
        Total_Length = total_Length;
    }

    public int getCommand_Id() {
        return Command_Id;
    }

    public void setCommand_Id(int command_Id) {
        Command_Id = command_Id;
    }

    public int getSequence_Id() {
        return Sequence_Id;
    }

    public void setSequence_Id(int sequence_Id) {
        Sequence_Id = sequence_Id;
    }
}
